home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 045a / btp15.zip / EXAMPLE2.PAS < prev    next >
Pascal/Delphi Source File  |  1991-11-08  |  4KB  |  126 lines

  1. program Example2;             { (C) 1991 John C. Leon   last updated 11/4/91 }
  2.  
  3. USES
  4.     BTP;
  5.  
  6. TYPE
  7.    ExampleFields  = record
  8.                        case integer of
  9.                        1: (First   : array[1..10] of char;
  10.                            Last    : array[1..20] of char;
  11.                            KeyBuf  : array[1..20] of char);
  12.                        2: (DBuffer : array[1..30] of char);
  13.                        3: (Position: array[1..2] of word);
  14.                        end;
  15.    PExample      = ^ExampleFile;
  16.    ExampleFile   = object(BFileExt)
  17.                       Fields: ExampleFields;
  18.                       function BT(OpCode, Key: integer): integer; virtual;
  19.                       function BTExt(OpCode, Key: integer): integer; virtual;
  20.                       function GetNumRecs:longint;
  21.                       function GetName: string;
  22.                       end;
  23.  
  24.  
  25. VAR
  26.    Example         : PExample;
  27.    NumberRecords   : longint;
  28.    x               : string;
  29.    Value           : TCharArray;
  30.    Counter         : integer;
  31.  
  32. (* Define methods of ExampleFile *)
  33. (* ------------------------------------------------------------------------ *)
  34.  
  35. function ExampleFile.BT(OpCode, Key:integer):integer;
  36. begin
  37.    DBufferLen := Specs.RecLen;
  38.    BT := Btrv(OpCode, PosBlk, Fields, DBufferLen, Fields.KeyBuf, Key);
  39. end;
  40.  
  41. {Despite the use of two different functions, thanks to OOP, we are assured
  42.  of using the precise position block, data buffer and key buffer required.}
  43. function ExampleFile.BTExt(OpCode, Key: integer): integer;
  44. begin
  45.    BStatus := BFileExt.BTExt(OpCode, Key);
  46.    BTExt := Btrv(OpCode, PosBlk, ExtDBuffer^.Entire, DBufferLen, Fields.KeyBuf,
  47.                  Key);
  48. end;
  49.  
  50. function ExampleFile.GetNumRecs: longint;
  51. begin
  52.    GetNumRecs := NumRecs;
  53. end;
  54.  
  55. function ExampleFile.GetName: string;
  56. var
  57.    First, Last : string;
  58. begin
  59.    First := RTrim(Fields.First);
  60.    Last  := RTrim(Fields.Last);
  61.    GetName := First + ' ' + Last;
  62. end;
  63.  
  64.  
  65. (* begin MAIN PROGRAM code *)
  66. (* ------------------------------------------------------------------------ *)
  67. BEGIN
  68.  
  69. Example := new(PExample, Init('Example', ReadOnly));
  70. if Example^.NumRecs = 0 then
  71.    begin
  72.    writeln('Please run Example2.EXE at least once to put a record in file.');
  73.    halt;
  74.    end;
  75.  
  76. with Example^ do
  77.    begin
  78.    Filter.MaxSkip := 50;
  79.    Filter.NumLogicTerms := 2;
  80.    Extractor.NumRecords := 5;
  81.    Extractor.NumFields  := 1;
  82.    end;
  83.  
  84. X := 'Leon';
  85. for Counter := 1 to length(X) do
  86.    Value[Counter] := X[Counter];
  87. for Counter := (length(X)+1) to 255 do
  88.    Value[Counter] := ' ';
  89.  
  90. with Example^.FilterSpec^ do
  91.    insert(new(PFilterSpec, InitV(BString, 20, 10, Equal, NextTermAnd, Value)));
  92.  
  93. X := 'John';
  94. for Counter := 1 to length(X) do
  95.    Value[Counter] := X[Counter];
  96. for Counter := (length(X)+1) to 255 do
  97.    Value[Counter] := ' ';
  98.  
  99. with Example^.FilterSpec^ do
  100.    insert(new(PFilterSpec, InitV(BString, 10, 0, Equal, LastTerm, Value)));
  101.  
  102. with Example^.ExtractorSpec^ do
  103.    insert(new(PExtSpec, Init(Example^.Specs.RecLen, 0)));
  104.  
  105. BStatus := Example^.BT(BGetFirst, Zero);
  106. writeln('Status of get first is ', BStatus);
  107.  
  108. BStatus := Example^.BTExt(BGetNextExt, Zero);
  109. writeln('Status of ext get next is ', BStatus);
  110.  
  111. writeln('Number of records with name ''John Leon'' is ',
  112.         Example^.ExtDBuffer^.NumRecs);
  113.  
  114. BStatus := Example^.Close;
  115. if BStatus = 0 then
  116.    writeln('EXAMPLE closed successfully.')
  117.    else
  118.    writeln('Problem closing EXAMPLE.  Status = ', BStatus);
  119.  
  120.  
  121. dispose(Example, Done);
  122.  
  123. END.
  124.  
  125.  
  126.